/* eslint valid-jsdoc: 'off' */

'use strict';
const fs = require('fs');
const path = require('path');
const Axios = require('axios');


/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};
  config.siteFile = {
    '/favicon.ico': fs.readFileSync(path.join(__dirname, 'favicon.png')),
  };
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1584326608945_8926';

  config.middleware = [ 'response', 'auth' ];
  config.auth = {
    ignore: [
      '/app/token',
    ],
  };

  config.cluster = {
    listen: {
      port: 7001,
      hostname: '0.0.0.0',
    },
  };

  config.all_schedule = {
    interval: 1*60*60*1000,
    // cron: '* */15 * * * *',
    immediate: true,
    disable: false,
    meanwhileNum: 1,
  };

  config.identify = {
    identification: 'com.rondaful.identify',
    expiresIn: '86400s',
    rsExpiresIn: '86400s',
  };

  config.sequelize = {
    delegate: 'model', // load all models to app.model and ctx.model
    baseDir: 'model', // load models from `app/model/*.js`
    dialect: 'mysql',
    database: 'tort-words',
    host: '172.20.0.134',
    username: 'tort',
    password: 't123!@#T',
    // database: 'tort-word-test',
    // host: '172.20.0.134',
    // username: 'tort-test-gxq',
    // password: 'cWCARx0YaP}I2~8S',
    port: '3306',
    timezone: '+08:00', // 东八时区
    logging: false,
    dialectOptions: {
      dateStrings: true,
      typeCast(field, next) {
        if (field.type === 'DATETIME') {
          return Date.parse(field.string());
        }
        return next();
      },
    },
  };
  config.erp = {
    baseUrl: 'http://oms.rondaful.com',
    secret_key: '318e26ed2a8c44993b126b9ab154493c',
    code: 'save_cite_tort_log',
    timeout: 60000,
    tokenTimeout: 3600 * 1000,
  };

  // config.erp = {
  //   baseUrl: 'http://172.18.8.245:81',
  //   secret_key: 'cddded31f112efaff1be4cd7b3e28644',
  //   code: 'save_cite_tort_log',
  //   timeout: 70000,
  //   tokenTimeout: 3600 * 1000
  // };
  // erp默认无需检测的规则 在抓取时自动加入软删除  纯数字、字母加点号、单字母、字母加数字组合
  config.erpRule = [ '^[0-9]*$', '^[A-Za-z][\.]$', '^[A-Za-z][0-9]*$' ];
  // erp默认仅需检测的源站点
  config.erpSite = [ 'USTM', 'CATM', 'DETM', 'FRTM', 'UKTM', 'ITTM', 'ESTM', 'AUTM', 'MXTM', 'JPTM', 'EMTM', 'MAD', 'US', 'CA', 'DE', 'FR', 'UK', 'IT', 'ES', 'AU', 'MX', 'JP', 'EM' ];
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
    maxAge: 3600,
    exposeHeaders: [ 'token' ],
  };
  config.redis = {
    client: {
      port: 6379,
      host: '172.20.0.141',
      password: '',
      db: 2,
    },
  };
  config.bull = {
    port: 6379, // Redis port
    host: '127.0.0.1', // Redis host
    password: '',
    db: 1,
  };
  config.worker = {
    page_size: 100000,
    ConcurrentFindNum: 10,
  };
  config.logrotator = {
    maxDays: 15,
  };
  config.queryCofig = {
    "p": {
        "search": {
            "fq": [
                {
                    "fi": "STATUS",
                    "te": "",
                    "co": "OR"
                },
                {
                    "fi": "SOURCE",
                    "te": "",
                    "co": "OR"
                }
            ]
        },
        "rows": 100,
        "start": 0
    },
    "type": "brand",
    "la": "en",
    "qi": '',
    "queue": 1
  };
  config.mysql_max_connections = 100;
  config.datas_start_time = '-5364662400000';
  config.run_max_time = 8*60*60*1000;
  return {
    ...config,
  };
};
